package com.ww.sound_emission.controller;

import com.ww.sound_emission.domain.Comments;
import com.ww.sound_emission.service.CommentsService;
import com.ww.sound_emission.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentsService commentService;

    // 获取所有评论
    @GetMapping
    public Result<List<Comments>> getAllComments() {
        List<Comments> comments = commentService.list();
        return Result.success(comments);
    }

    // 添加评论
    @PostMapping
    public Result<String> addComment(@RequestBody Comments comment) {
        commentService.save(comment);
        return Result.success("评论添加成功");
    }

    // 删除评论
    @DeleteMapping("/{id}")
    public Result<String> deleteComment(@PathVariable Long id) {
        commentService.removeById(id);
        return Result.success("评论删除成功");
    }
}